package yjpay.merchant.web.control;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import yjpay.service.MerchantAPIService;

/**
 * 商户通用接口——退款
 * 
 * @author junqinghuang
 * 
 */
@Controller
public class MerchantRefundWebCtrl {

	@Resource(name = "merchantAPIService")
	private MerchantAPIService merchantAPIService;

	@RequestMapping(value = "/merchant/to_refund")
	public String toMerchantQuery() {
		return "merchant/merchant_refund.jsp";
	}

	@RequestMapping(value = "/merchant/refund")
	@ResponseBody
	public ModelAndView merchantQueryOrder(
			@RequestParam("refund_orderid") String orderid,
			@RequestParam("refund_yborderid") String origyborderid,
			@RequestParam("refund_amount") String amount,
			@RequestParam("refund_cause") String cause, Model model)
			throws Exception {

		String currency = "156";
		String res = merchantAPIService.driectRefund(orderid, origyborderid,
				amount, currency, cause);

		ModelAndView modelAndView = new ModelAndView();
		modelAndView.setViewName("pay/pay_result.jsp");
		modelAndView.addObject("apiname", "直接退款接口（商户通用接口）");
		modelAndView.addObject("payresult_view", res);

		return modelAndView;
	}
}
